//
//  SearchViewController.m
//  TouTiao
//
//  Created by 杜倩 on 16/9/12.
//  Copyright © 2016年 Match. All rights reserved.
//

#import "SearchViewController.h"
#import "SearchTwoController.h"
#import "TitleBar.h"

#import <JavaScriptCore/JavaScriptCore.h>

@interface SearchViewController ()<UISearchBarDelegate,UIWebViewDelegate>
//搜索按钮
@property(nonatomic,strong)UIButton *btn;

@end

@implementation SearchViewController

#pragma mark 加载时调用
- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self addBackLeft];//返回按钮
    [self addItemSearch];//搜索关注

    UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    
    webView.delegate = self;
    
    [self.view addSubview:webView];
    
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://is.snssdk.com/concern/v1/guide/page/?ab_client=a1,b1,b7,f2,f7,e1&iid=5367541212&ac=WIFI&ssmix=a&aid=13&app_name=news_article&channel=App%20Store&device_platform=iphone&idfa=108DA0E6-A67D-4105-A28B-2972A736B851&os_version=9.3.5&vid=DDD24FC1-6D4E-4F1B-98E7-24388DD52A94&openudid=ab26a72deb8a4e4e29c7373d0a581bcf553ecafb&device_type=iPhone8,1&ab_feature=z1&ab_group=z1&device_id=15981303842&ab_version=72388,83097,79286&resolution=750*1334&version_code=5.7.7"]]];
    
    
}

#pragma mark 左边的返回键
-(void)addBackLeft{
    //设置导航栏的背景颜色
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];

    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    //设置按钮内边距
    button.contentEdgeInsets=UIEdgeInsetsMake(0, -5, 0, 0);//返回按钮箭头距离边缘的大小
    
    [button setImage:[UIImage imageNamed:@"leftbackicon_sdk_login@2x.png"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"leftbackicon_white_titlebar@2x"] forState:UIControlStateHighlighted];
    
    UIBarButtonItem *item=[[UIBarButtonItem alloc] initWithCustomView:button];
    [button sizeToFit];//自动适应大小
    [button addTarget:self action:@selector(goToBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationController.interactivePopGestureRecognizer.delegate = nil;//清空手势，实现拖拽
    self.navigationItem.leftBarButtonItem=item;
    
    
    
}
#pragma Mark 返回按钮的单击事件
-(void)goToBack{
    self.tabBarController.tabBar.hidden=NO;//返回显示标签栏
    [self.navigationController popToRootViewControllerAnimated:YES];//返回上一级控制器

}

#pragma mark 搜索关注的
-(void)addItemSearch{
    
    //搜索栏
    _btn=[[UIButton alloc]init];
    _btn.frame=CGRectMake(40, 10, [UIScreen mainScreen].bounds.size.width - 50 - 40, 20);
    
    [_btn setTitle:@"搜索" forState:UIControlStateNormal];
    
    _btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_btn setImage:[UIImage imageNamed:@"detail_search_icon"] forState:UIControlStateNormal];
    _btn.backgroundColor=[UIColor whiteColor];
    _btn.alpha = 0.7;
    [_btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView=_btn;
    
}

#pragma mark 搜索的单击事件
-(void)btn:(UIButton *)sender{
    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"SearchTwoController" bundle:nil];
    SearchTwoController *two = [storyboard instantiateInitialViewController];
    [self.navigationController pushViewController:two animated:YES];
    
}

@end
